home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Ports / mac / dprintf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-06  |  2.1 KB  |  93 lines  |  [TEXT/????]

  1. /* A simple debugging routine, assuming you've got QuickDraw,
  2.    windows and menus running.
  3.    It can be called with up to 10 printf arguments.
  4.  
  5.    It beeps, draws a message over the menu bar,
  6.    and waits for a key or mouse down event.
  7.    If Command-Period is detected, it calls ExitToShell,
  8.    to allow an emergency exit from a looping program.
  9.  
  10.    Warning: there are some side effects on the window manager's port,
  11.    such as pen parameters and clipping.
  12.    The printed string shouldn't exceed 255 chars.
  13. */
  14.  
  15. #include "macwin.h"
  16. #include <stdarg.h>
  17.  
  18. #ifdef MPW
  19. #include <Events.h>
  20. #include <Menus.h>
  21. #include <OSUtils.h>
  22. #include <SegLoad.h>
  23. #endif
  24.  
  25. void
  26. dprintf(char *fmt, ...)
  27. {
  28.     char buf[256];
  29.     GrafPtr saveport;
  30.     GrafPtr screen;
  31.     Rect r;
  32.     va_list p;
  33.     
  34.     SysBeep(2);
  35.     va_start(p, fmt);
  36.     vsprintf(buf, fmt, p);
  37.     va_end(p);
  38.     GetPort(&saveport);
  39.     GetWMgrPort(&screen);
  40.     SetPort(screen);
  41.     r= screen->portRect;
  42.     r.bottom= 19; /* Height of menu bar, less border line */
  43.     ClipRect(&r);
  44.     PenNormal();
  45.     /* Reset more parameters, such as text font? */
  46.     EraseRect(&r);
  47.     MoveTo(5, 15); /* Left margin and base line */
  48. #ifndef CLEVERGLUE
  49.     CtoPstr(buf);
  50. #endif
  51.     DrawString(buf);
  52.     
  53.     /* Wait for mouse or key down event.
  54.        Include auto key events so a flood of dprintf
  55.        calls can be skipped quickly by holding a key. */
  56.     for (;;) {
  57.         EventRecord e;
  58.         
  59.         if (GetNextEvent(keyDownMask|autoKeyMask|mDownMask, &e)) {
  60.             if (e.what == keyDown &&
  61.                 (e.message & charCodeMask) == '.' &&
  62.                 (e.modifiers & cmdKey))
  63.                 ExitToShell();
  64.             if ((e.what == keyDown || e.what == autoKey) &&
  65.                 ((e.message & charCodeMask) == '\r' ||
  66.                  (e.message & charCodeMask) == '\3')
  67.                 || e.what == mouseDown)
  68.                 break;
  69.         }
  70.     }
  71.     
  72.     /* Restore the situation, more or less. */
  73.     SetPort(saveport);
  74.     DrawMenuBar();
  75. }
  76.  
  77. #ifdef UNUSED
  78.  
  79. /* Print the extent of the stack. */
  80.  
  81. #define CurStackBase    (* (long*)0x908)
  82. #define ApplZone    (* (long*)0x2AA)
  83. #define ApplLimit    (* (long*)0x130)
  84.  
  85. prstack(where)
  86.     char *where;
  87. {
  88.     dprintf("ApplZone=%d, ApplLimit=%d, CurStackBase=%d, SP=%d",
  89.         ApplZone, ApplLimit, CurStackBase, &where);
  90. }
  91.  
  92. #endif /*UNUSED*/
  93.